'use strict';

module.exports = app => {
  const { INTEGER, STRING, DATE, DECIMAL } = app.Sequelize;

  const OutgoingInvoice = app.model.define('outgoing_invoice', {
    id: {
      type: INTEGER,
      primaryKey: true,
      autoIncrement: true
    },
    invoiceNumber: {
      type: STRING(50),
      allowNull: false,
      field: 'invoice_number',
      comment: '发票号码'
    },
    invoiceCode: {
      type: STRING(50),
      allowNull: true,
      field: 'invoice_code',
      comment: '发票代码'
    },
    invoiceTypeCode: {
      type: STRING(10),
      allowNull: true,
      field: 'invoice_type_code',
      comment: '发票类型代码'
    },
    invoiceKindCode: {
      type: STRING(10),
      allowNull: true,
      field: 'invoice_kind_code',
      comment: '发票种类代码'
    },
    invoiceStatusCode: {
      type: STRING(10),
      allowNull: true,
      field: 'invoice_status_code',
      comment: '发票状态代码'
    },
    isRedInvoice: {
      type: STRING(1),
      allowNull: true,
      field: 'is_red_invoice',
      comment: '是否红字发票(Y/N)'
    },
    sellerTaxNumber: {
      type: STRING(50),
      allowNull: true,
      field: 'seller_tax_number',
      comment: '销方识别号'
    },
    sellerName: {
      type: STRING(200),
      allowNull: true,
      field: 'seller_name',
      comment: '销方名称'
    },
    buyerTaxNumber: {
      type: STRING(50),
      allowNull: true,
      field: 'buyer_tax_number',
      comment: '购方识别号'
    },
    buyerName: {
      type: STRING(200),
      allowNull: true,
      field: 'buyer_name',
      comment: '购方名称'
    },
    invoiceDate: {
      type: DATE,
      allowNull: true,
      field: 'invoice_date',
      comment: '开票日期'
    },
    totalAmount: {
      type: DECIMAL(15, 2),
      allowNull: true,
      field: 'total_amount',
      comment: '金额'
    },
    taxAmount: {
      type: DECIMAL(15, 2),
      allowNull: true,
      field: 'tax_amount',
      comment: '税额'
    },
    totalTaxAmount: {
      type: DECIMAL(15, 2),
      allowNull: true,
      field: 'total_tax_amount',
      comment: '价税合计'
    },
    invoiceSource: {
      type: STRING(50),
      allowNull: true,
      field: 'invoice_source',
      comment: '发票来源'
    },
    issuer: {
      type: STRING(50),
      allowNull: true,
      field: 'issuer',
      comment: '开票人'
    },
    taxBureauCode: {
      type: STRING(20),
      allowNull: true,
      field: 'tax_bureau_code',
      comment: '税务机关代码'
    },
    taxBureauName: {
      type: STRING(100),
      allowNull: true,
      field: 'tax_bureau_name',
      comment: '税务机关名称'
    },
    organizationId: {
      type: INTEGER,
      allowNull: false,
      field: 'organization_id',
      comment: '组织ID'
    },
    createdAt: {
      type: DATE,
      field: 'created_at'
    },
    updatedAt: {
      type: DATE,
      field: 'updated_at'
    }
  }, {
    tableName: 'outgoing_invoices',
    timestamps: true,
    createdAt: 'created_at',
    updatedAt: 'updated_at'
  });

  return OutgoingInvoice;
};